﻿using System;
namespace Kis.Xroad.Eu {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="TypeWithAttributes", Namespace="http://kis.x-road.eu/", Target=typeof(TypeWithAttributes))]
    public class TypeWithAttributesSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected TypeWithAttributes clazz;
        
        public TypeWithAttributesSerializer(TypeWithAttributes clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXmlAttributes(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXmlAttributes(Writer);
            if (clazz.BuiltInAttributeWithDefaultValue!=null) {
                Writer.WriteAttributeString("builtInAttributeWithDefaultValue", new global::Xtee.Core.Schema.XsdInt(((int)(clazz.BuiltInAttributeWithDefaultValue))).ToString());
            }
            Writer.WriteAttributeString("builtinAttributeRequired", new global::Xtee.Core.Schema.XsdInt(((int)(clazz.BuiltinAttributeRequired))).ToString());
            if (clazz.BuiltInAttribute!=null) {
                Writer.WriteAttributeString("builtInAttribute", new global::Xtee.Core.Schema.XsdInt(((int)(clazz.BuiltInAttribute))).ToString());
            }
            if (clazz.UserDefinedAttributeWithDefaultValue!=null) {
                Writer.WriteAttributeString("userDefinedAttributeWithDefaultValue", new global::Kis.Xroad.Eu.WorkDay(clazz.UserDefinedAttributeWithDefaultValue).ToString());
            }
            if (clazz.UserDefinedAttribute!=null) {
                Writer.WriteAttributeString("userDefinedAttribute", new global::Kis.Xroad.Eu.WorkDay(clazz.UserDefinedAttribute).ToString());
            }
            if (clazz.ReferedUserDefinedAttribute!=null) {
                Writer.WriteAttributeString("referedUserDefinedAttribute", new global::Kis.Xroad.Eu.WorkDay(clazz.ReferedUserDefinedAttribute).ToString());
            }
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
        }
        
        public override void ReadXmlAttributes(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXmlAttributes(Reader);
            var builtInAttributeWithDefaultValueValue = Reader.GetAttribute("builtInAttributeWithDefaultValue");
            if ((builtInAttributeWithDefaultValueValue != null)) {
                clazz.BuiltInAttributeWithDefaultValue = new global::Xtee.Core.Schema.XsdInt(builtInAttributeWithDefaultValueValue).Value;
            }
            var builtinAttributeRequiredValue = Reader.GetAttribute("builtinAttributeRequired");
            if ((builtinAttributeRequiredValue != null)) {
                clazz.BuiltinAttributeRequired = new global::Xtee.Core.Schema.XsdInt(builtinAttributeRequiredValue).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.AttributeRequiredException(">>TypeWithAttributes>builtinAttributeRequired");
            }
            var builtInAttributeValue = Reader.GetAttribute("builtInAttribute");
            if ((builtInAttributeValue != null)) {
                clazz.BuiltInAttribute = new global::Xtee.Core.Schema.XsdInt(builtInAttributeValue).Value;
            }
            var userDefinedAttributeWithDefaultValueValue = Reader.GetAttribute("userDefinedAttributeWithDefaultValue");
            if ((userDefinedAttributeWithDefaultValueValue != null)) {
                clazz.UserDefinedAttributeWithDefaultValue = new global::Kis.Xroad.Eu.WorkDay(userDefinedAttributeWithDefaultValueValue);
            }
            var userDefinedAttributeValue = Reader.GetAttribute("userDefinedAttribute");
            if ((userDefinedAttributeValue != null)) {
                clazz.UserDefinedAttribute = new global::Kis.Xroad.Eu.WorkDay(userDefinedAttributeValue);
            }
            var referedUserDefinedAttributeValue = Reader.GetAttribute("referedUserDefinedAttribute");
            if ((referedUserDefinedAttributeValue != null)) {
                clazz.ReferedUserDefinedAttribute = new global::Kis.Xroad.Eu.WorkDay(referedUserDefinedAttributeValue);
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        }
    }
}
